home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / share / prog_compatible.lua < prev    next >
Text File  |  2005-07-16  |  3KB  |  119 lines

  1. -- -----------------------------------------------------------------
  2. -- There are functions used in levels to raise dialogs and animation
  3. -- -----------------------------------------------------------------
  4.  
  5. file_include("script/share/prog_goanim.lua")
  6. file_include("script/share/prog_finder.lua")
  7.  
  8. -- -----------------------------------------------------------------
  9. -- Compatibility functions
  10. -- -----------------------------------------------------------------
  11. function no_dialog()
  12.     return not dialog_isDialog() and not game_isPlanning()
  13. end
  14.  
  15. function isReady(model)
  16.     -- fish is ready for dialog
  17.     return model:isAlive() and not model:isOut()
  18. end
  19.  
  20. function odd(number)
  21.     return math.mod(number, 2) == 1
  22. end
  23.  
  24. function getRestartCount()
  25.     return level_getRestartCounter()
  26. end
  27.  
  28. -- -----------------------------------------------------------------
  29. -- Planning
  30. -- -----------------------------------------------------------------
  31. function addm(time, text)
  32.     small:planDialog(time, text)
  33. end
  34. function addv(time, text)
  35.     big:planDialog(time, text)
  36. end
  37. function adddel(time)
  38.     -- plan delay
  39.     planTimeAction(time, function() end)
  40. end
  41.  
  42. function planSet(model, variable_name, value)
  43.     -- plan value set, variable_name must be string
  44.     planTimeAction(0, function() model[variable_name] = value end)
  45. end
  46. function planDialogSet(time, text, value, model, variable_name)
  47.     -- plan value set, and unset after dialog end
  48.     model:planDialog(time, text, function() model[variable_name] = value end)
  49.     planTimeAction(0, function() model[variable_name] = 0 end)
  50. end
  51.  
  52. function planBusy(model, value, delay)
  53.     if delay == nil then
  54.         delay = 0
  55.     end
  56.     planTimeAction(delay, function()
  57.             model:setBusy(value)
  58.         end)
  59. end
  60.  
  61. -- -----------------------------------------------------------------
  62. -- Distance measuring
  63. -- -----------------------------------------------------------------
  64. function xdist(one, second)
  65.     local result = 0
  66.     local one_min = one.X
  67.     local one_max = one.X + one:getW() - 1
  68.     local second_min = second.X
  69.     local second_max = second.X + second:getW() - 1
  70.     if one_max < second_min then
  71.         result = one_max - second_min
  72.     elseif second_max < one_min then
  73.         result = one_min - second_max
  74.     else
  75.         result = 0
  76.     end
  77.     return result
  78. end
  79. function ydist(one, second)
  80.     local result = 0
  81.     local one_min = one.Y
  82.     local one_max = one.Y + one:getH() - 1
  83.     local second_min = second.Y
  84.     local second_max = second.Y + second:getH() - 1
  85.     if one_max < second_min then
  86.         result = one_max - second_min
  87.     elseif second_max < one_min then
  88.         result = one_min - second_max
  89.     else
  90.         result = 0
  91.     end
  92.     return result
  93. end
  94. function dist(one, second)
  95.     local dx = math.abs(xdist(one, second))
  96.     local dy = math.abs(ydist(one, second))
  97.     return math.max(dx, dy)
  98. end
  99.  
  100. function look_at(fish, object)
  101.     local dx = xdist(fish, object)
  102.     return (fish:isLeft() and dx > 0) or (not fish:isLeft() and dx < 0)
  103. end
  104.  
  105. -- -----------------------------------------------------------------
  106. -- Alternative for FArray
  107. -- -----------------------------------------------------------------
  108. function modelEquals(model, x, y)
  109.     -- Compares this model and model on [x,y] position
  110.     -- index -1 is for empty space (water)
  111.     return model_equals(model.index, x, y)
  112. end
  113.  
  114. function isWater(x, y)
  115.     -- Compares model on [x,y] position
  116.     return model_equals(-1, x, y)
  117. end
  118.  
  119.